import { Injectable } from '@nestjs/common';
import { CreateCardDto } from './dto/create-card.dto';
import { UpdateCardDto } from './dto/update-card.dto';
import { Card } from './entities/card.entity';

@Injectable()
export class CardService {
  create(createCardDto: CreateCardDto) {
    return Card.save({
      ...createCardDto,
      isShow: true,
      create_time: new Date(),
      update_time: new Date(),
      delete_time: null,
    });
  }

  async findAll(pageNum: number, pageSize: number) {
    const [list, count] = await Card.findAndCount({
      skip: (pageNum - 1) * pageSize,
      take: pageSize,
    });

    return { list, count };
  }

  findOne(id: number) {
    return Card.findOneBy({ id });
  }

  update(id: number, updateCardDto: UpdateCardDto) {
    return Card.update(id, { ...updateCardDto });
  }

  remove(id: number) {
    return Card.update(id, { delete_time: new Date() });
  } 
}
